package com.yue.zookeeper;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/11/1<br/>
 *
 * @author QiuYang
 */
public class ZookeeperTest {
    public static void main(String[] args) {
        BaseZookeeper baseZookeeper = new BaseZookeeper();
        String host = "localhost:2181";
        String path = "/test";
        String root = "/";

        try {
            baseZookeeper.connectZookeeper(host);
            System.out.println("----------connect zookeeper ok-----------");

            byte[] data = "12345".getBytes();
            String result = baseZookeeper.creatNode(path, data);
            System.out.println(result);
            System.out.println("----------create node ok-----------");

            List<String> children = baseZookeeper.getChildren(root);
            children.forEach(child -> System.out.println(child));
            System.out.println("----------get children ok-----------");

            byte[] nodeData = baseZookeeper.getData(path);
            System.out.println(new String(nodeData));
            System.out.println("----------get data ok-----------");

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
}
